package com.yusheng.controller;

import com.yusheng.domain.R;
import com.yusheng.tr.common.core.utils.minio.MinioUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@Tag(name = "文件服务")
public class FileController {

    @Autowired
    private MinioUtils minioUtils;

    @PostMapping("/upload")
    @Operation(summary = "上传文件")
    @Parameters({
            @Parameter(name = "file",description = "文件"),
            @Parameter(name = "bucketName",description = "上传位置"),
    })
    public R<?> upload(@RequestPart("file") MultipartFile file, @RequestParam("bucketName") String bucketName) throws Exception {
        return R.ok(minioUtils.uploadFile(file, bucketName));
    }
}
